package com.fsquare.domain.invoice;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.Table;

import org.broadleafcommerce.common.admin.domain.AdminMainEntity;
import org.broadleafcommerce.common.presentation.AdminPresentation;
import org.broadleafcommerce.common.presentation.AdminPresentationClass;
import org.broadleafcommerce.common.presentation.client.SupportedFieldType;
import org.broadleafcommerce.common.presentation.client.VisibilityEnum;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import com.fsquare.service.invoice.type.TemplateType;


@Entity
@Table(name="BLC_INVOICE")
@Inheritance(strategy = InheritanceType.JOINED)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region="blStandardElements")
@AdminPresentationClass(friendlyName = "InvoiceImpl")
public class InvoiceImpl implements Invoice, AdminMainEntity {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4482522761794130967L;

	@Id
    @GeneratedValue(generator = "InvoiceId")
    @GenericGenerator(
        name="InvoiceId",
        strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
        parameters = {
            @Parameter(name="segment_value", value="SystemPropertyImpl"),
            @Parameter(name="entity_name", value="oInvoiceImpl")
        }
    )
    @Column(name = "INVOICE_ID")
    protected Long id;
	
	@Column(name = "NAME", nullable = false)
    @AdminPresentation(friendlyName = "InvoiceImpl_name", order = 1000, group = "InvoiceImpl_general", groupOrder = 1000, prominent = true, gridOrder = 1000)
    protected String name;

    @Column(name= "VALUE", columnDefinition = "TEXT")
    @AdminPresentation(friendlyName = "InvoiceImpl_value", order = 2000,
        group = "InvoiceImpl_general", groupOrder = 1000, prominent = true, gridOrder = 3000)
    protected String value;
    
    @Column(name = "TYPE", nullable=false)
	@Enumerated(EnumType.STRING)
    @AdminPresentation(friendlyName = "InvoiceImpl_template_type", 
    order = 1000, group = "InvoiceImpl_general", 
    groupOrder = 1000, prominent = true, gridOrder = 1000, fieldType=SupportedFieldType.EXPLICIT_ENUMERATION)
	private TemplateType templateType = TemplateType.INVOICE;
    
    @Column(name = "LOB_VALUE", length = Integer.MAX_VALUE-1)
    @Lob
    @Type(type = "org.hibernate.type.StringClobType")
    @AdminPresentation(friendlyName = "InvoiceImpl_value", order = 2000,
    group = "InvoiceImpl_lobValue", fieldType = SupportedFieldType.HTML, groupOrder = 1000, prominent = true, gridOrder = 3000)
    protected String lobValue;
    
    @Column(name= "IN_USE")
    @AdminPresentation(friendlyName = "InvoiceImpl_inUse", order = 3000,
        group = "InvoiceImpl_general", groupOrder = 1000, prominent = true, gridOrder = 3000)
    protected boolean inUse;
    
    @Column(name= "FILE",columnDefinition="longblob")
    @AdminPresentation(friendlyName = "InvoiceImpl_file", order = 4000, fieldType=SupportedFieldType.UPLOAD, visibility=VisibilityEnum.GRID_HIDDEN,
    group = "InvoiceImpl_general", groupOrder = 1000, prominent = true, gridOrder = 3000)
    private byte[] file;
    
    @Column(name = "FILE_NAME")
    @AdminPresentation(friendlyName = "InvoiceImpl_file_name", order = 4000, readOnly=true,
    group = "InvoiceImpl_general", groupOrder = 1000, prominent = true, gridOrder = 3000)
    protected String fileName;
    
    @Column(name = "CONTENT_TYPE")
    protected String contentType;
    
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean isInUse() {
		return inUse;
	}

	public void setInUse(boolean inUse) {
		this.inUse = inUse;
	}

	public String getLobValue() {
		return lobValue;
	}

	public void setLobValue(String lobValue) {
		this.lobValue = lobValue;
	}

	public byte[] getFile() {
		return file;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	
	public void setFile(byte[] file) {
		this.file = file;
	}
	
	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	
	public TemplateType getTemplateType() {
		return templateType;
	}

	public void setTemplateType(TemplateType templateType) {
		this.templateType = templateType;
	}

	@Override
	public String getMainEntityName() {
		return getName();
	}
	
	
}
